#version 300 es
precision mediump float;

in vec4 v_color;
in vec2 v_texCoord;
in vec2 v_position2d;
in vec2 v_viewPosition2d;

uniform sampler2D u_texture;
uniform vec2 u_viewSize;
uniform vec2 u_lightPosition2d;

out vec4 fragColor;

void main() {
    vec4 texColor = texture(u_texture, v_texCoord) * v_color;

    if(texColor.a <= 0.0){
    	fragColor = vec4(0.0, 0.0, 0.0, 1.0);
    	return;
    }

    //fragColor = vec4(texColor.r, texColor.g, texColor.b, texColor.a);
    //fragColor = vec4(1.0, 1.0, 1.0, -1.0);

//    vec3 finalColor = texColor.rgb * (v_viewPosition2d.x < 0.5 && v_viewPosition2d.y < 0.5 ? 1.0 : 0.3);
//    fragColor = vec4(finalColor, texColor.a);

    float viewWidthRatio = u_viewSize.x / u_viewSize.y;
    vec2 delta = v_viewPosition2d - u_lightPosition2d;
    delta.x *= viewWidthRatio;
    float dist = length(delta);
    float lightSpread = 0.3;
    float intensity = (lightSpread - dist) / lightSpread;

    vec3 finalColor = texColor.rgb * intensity;
    fragColor = vec4(finalColor, texColor.a);
}
